package com.baidu.location;

import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Message;
import android.os.Messenger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

final class m
{
  public String a = null;
  public Messenger b = null;
  public k c = new k();
  public int d = 0;

  public m(l paraml, Message paramMessage)
  {
    this.b = paramMessage.replyTo;
    this.a = paramMessage.getData().getString("packName");
    this.c.f = paramMessage.getData().getString("prodName");
    ak.ak = this.a;
    ak.al = this.c.f;
    this.c.a = paramMessage.getData().getString("coorType");
    this.c.b = paramMessage.getData().getString("addrType");
    ak.g = this.c.b;
    this.c.c = paramMessage.getData().getBoolean("openGPS");
    this.c.d = paramMessage.getData().getInt("scanSpan");
    this.c.e = paramMessage.getData().getInt("timeOut");
    this.c.g = paramMessage.getData().getInt("priority");
    this.c.h = paramMessage.getData().getBoolean("location_change_notify");
  }

  private void a(int paramInt)
  {
    Message localMessage = Message.obtain(null, paramInt);
    try
    {
      if (this.b != null)
        this.b.send(localMessage);
      this.d = 0;
      return;
    }
    catch (Exception localException)
    {
      if (localException instanceof DeadObjectException);
      this.d += 1;
    }
  }

  private void a(int paramInt, String paramString1, String paramString2)
  {
    Bundle localBundle = new Bundle();
    localBundle.putString(paramString1, paramString2);
    paramString1 = Message.obtain(null, paramInt);
    paramString1.setData(localBundle);
    try
    {
      if (this.b != null)
        this.b.send(paramString1);
      this.d = 0;
      return;
    }
    catch (Exception paramString1)
    {
      if (paramString1 instanceof DeadObjectException);
      this.d += 1;
    }
  }

  public final void a()
  {
    if (this.c.h == true)
    {
      if (!(ak.b))
        break label24;
      a(54);
    }
    return;
    label24: a(55);
  }

  public final void a(String paramString)
  {
    if (paramString == null)
      return;
    a(27, "locStr", paramString);
    String str = paramString;
    if (this.c.a != null)
    {
      str = paramString;
      if (!(this.c.a.equals("gcj02")))
      {
        double d1 = ak.c(paramString, "x\":\"", "\"");
        double d2 = ak.c(paramString, "y\":\"", "\"");
        str = paramString;
        if (d1 != 4.9E-324D)
        {
          str = paramString;
          if (d2 != 4.9E-324D)
          {
            double[] arrayOfDouble = Jni.a(d1, d2, this.c.a);
            if (arrayOfDouble[0] <= 0.0D)
            {
              str = paramString;
              if (arrayOfDouble[1] <= 0.0D)
                break label148;
            }
            str = ak.a(ak.a(paramString, "x\":\"", "\"", arrayOfDouble[0]), "y\":\"", "\"", arrayOfDouble[1]);
          }
        }
      }
    }
    label148: a(21, "locStr", str);
  }

  public final void a(String paramString, int paramInt)
  {
    double d1;
    double d2;
    String str;
    ak.e();
    if (paramString == null)
      return;
    if (paramInt == 21)
      a(27, "locStr", paramString);
    Object localObject1 = paramString;
    if (this.c.a != null)
    {
      localObject1 = paramString;
      if (!(this.c.a.equals("gcj02")))
      {
        d1 = ak.c(paramString, "x\":\"", "\"");
        d2 = ak.c(paramString, "y\":\"", "\"");
        new StringBuilder("decode...").append(d1).append(":").append(d2);
        ak.e();
        str = paramString;
        if (d1 != 4.9E-324D)
        {
          str = paramString;
          if (d2 != 4.9E-324D)
          {
            localObject1 = Jni.a(d1, d2, this.c.a);
            str = ak.a(ak.a(paramString, "x\":\"", "\"", localObject1[0]), "y\":\"", "\"", localObject1[1]);
            new StringBuilder("decode2 ...").append(localObject1[0]).append(":").append(localObject1[1]);
            ak.e();
            ak.e();
          }
        }
        localObject1 = str;
        if (!(this.c.j));
      }
    }
    try
    {
      paramString = new JSONObject(str);
      Object localObject2 = paramString.getJSONObject("result");
      JSONObject localJSONObject1 = paramString.getJSONObject("content");
      localObject1 = str;
      if (Integer.parseInt(((JSONObject)localObject2).getString("error")) == 161)
      {
        localObject1 = localJSONObject1.getJSONObject("poi");
        localObject2 = ((JSONObject)localObject1).getJSONArray("p");
        int i = 0;
        while (i < ((JSONArray)localObject2).length())
        {
          JSONObject localJSONObject2 = ((JSONArray)localObject2).getJSONObject(i);
          d1 = Double.parseDouble(localJSONObject2.getString("x"));
          d2 = Double.parseDouble(localJSONObject2.getString("y"));
          if ((d1 == 4.9E-324D) || (d2 == 4.9E-324D))
            continue;
          double[] arrayOfDouble = Jni.a(d1, d2, this.c.a);
          localJSONObject2.put("x", String.valueOf(arrayOfDouble[0]));
          localJSONObject2.put("y", String.valueOf(arrayOfDouble[1]));
          ((JSONArray)localObject2).put(i, localJSONObject2);
          i += 1;
        }
        ((JSONObject)localObject1).put("p", localObject2);
        localJSONObject1.put("poi", localObject1);
        paramString.put("content", localJSONObject1);
        localObject1 = paramString.toString();
      }
      a(paramInt, "locStr", (String)localObject1);
      return;
    }
    catch (JSONException paramString)
    {
      paramString.printStackTrace();
      localObject1 = str;
    }
  }

  public final void b(String paramString)
  {
    if (this.c.h != true)
      return;
    a(paramString);
  }
}